def auto_commit_rollback(func):
    def wrapper(*args, **kwargs):
        try:
            result = func(*args, **kwargs)
            args[0].session.commit()  # 提交事务
            return result
        except Exception as e:
            args[0].session.rollback()  # 回滚事务
            raise e
    return wrapper